package com.ruoyi.web.controller.common;


import com.ruoyi.Apps.Utils.PhoneUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.SmsCodeBody;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.tools.sms.ISmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "短信验证码")
@RestController
public class SmsSendController {

    @Autowired
    ISmsService smsService;

    private static final Logger log = LoggerFactory.getLogger(SmsSendController.class);

    @ApiOperation("发送短信验证码")
    @PostMapping("/sendSmsCode")
    public AjaxResult SmsSendKaptcha(@Validated @RequestBody SmsCodeBody codeBody)
    {
        String phoneNumber = codeBody.getPhone();

        if(PhoneUtil.isMobile(phoneNumber)){
            AjaxResult ajax = AjaxResult.success();
            String uuid = smsService.sendSms(codeBody);
           if(StringUtils.isEmpty(uuid))
           {
               return AjaxResult.error("短信发送失败！");
           }
            ajax.put("data",uuid);
            return ajax;

        }
        return AjaxResult.error("请输入正确的手机号码！");
    }


}
